import 'Include.dart';
import 'model/User.dart';

//程序入口
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  /// 创建Store，引用 GSYState 中的 appReducer 创建 Reducer
  /// initialState 初始化 State
  final store = new Store<JvtdState>(
    appReducer,
    initialState: new JvtdState(
        userInfo: User.empty(),
        themeData: new ThemeData(
          primarySwatch: JvtdColor.THEME_COLOR,
        ),
        locale: Locale(JvtdString.ZH, JvtdString.CH)),
  );

  @override
  Widget build(BuildContext context) {
    final router = new Router();
    Routes.configureRoutes(router);
    Application.router = router;
    return StoreProvider(
      store: store,
      child: StoreBuilder<JvtdState>(builder: (context, store) {
        return MaterialApp(
          ///多语言实现代理
          localizationsDelegates: [
            JvtdStringLocalizedDelegate.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          locale: store.state.locale,
          theme: store.state.themeData,
          supportedLocales: [store.state.locale],
          onGenerateRoute: Application.router.generator,
        );
      }),
    );
  }
}
